﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;


namespace Candy.Web.Data
{
    public partial class FamilyDto
    {
        private string _path;
        public string Path
        {
            get
            {
                if (string.IsNullOrEmpty(_path))
                {
                    if (ParentId.HasValue)
                    {
                        var parent = EntitySet.Cast<FamilyDto>().FirstOrDefault(x => x.Id == this.ParentId);
                        if (parent != null)
                            _path = parent.Path + "\\" + Name;
                        else
                            throw new InvalidOperationException("Parent family not found.");
                        }
                    else
                        _path = Name;
                }
                return _path;
            }

        }

        protected override void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            if (e.PropertyName == "Name")
            {
                _path = null;
                RaisePropertyChanged("Path");
            }
        }
    }
}
